/******************************************************************************/
/* @ All Rights Reserved Copyright (C) 2015 broada,Ltd.                       */
/*                                                                            */
/*  NAME      = udp_core.h                                             */
/*  NOTE      =                                                               */
/*  DATE      = 2015/03/05 by guojq                                           */
/******************************************************************************/
#ifndef _SYNCMODULE_CORE_H_
#define _SYNCMODULE_CORE_H_

#include "conntrack.h"
#include "module.h"

#define APM_UDP_DBG 0
#define APM_UDP_ENABLE_COLOR_PRINT 1    // 是否启用彩色打印

#if APM_UDP_ENABLE_COLOR_PRINT
#define KRED        "\x1B[0;31m"
#define KRED_BACK   "\x1B[7;31m"
#define KSALMON     "\x1B[1;31m"
#define KGREEN      "\x1B[0;32m"
#define KLIMEGREEN  "\x1B[1;32m"
#define KYELLOW     "\x1B[0;33m"
#define KORANGE     "\x1B[0;34m"
#define KBLUE       "\x1B[1;34m"
#define KMAGENTA    "\x1B[0;35m"
#define KPINK       "\x1B[1;35m"
#define KCYAN       "\x1B[0;36m"
#define RESET       "\x1B[0m"
#else
#define KRED        ""
#define KRED_BACK   ""
#define KSALMON     ""
#define KGREEN      ""
#define KLIMEGREEN  ""
#define KYELLOW     ""
#define KORANGE     ""
#define KBLUE       ""
#define KMAGENTA    ""
#define KPINK       ""
#define KCYAN       ""
#define RESET       ""
#endif


#if APM_UDP_DBG
#define UDP_PRINT(...) printf(__VA_ARGS__)
#define UDP_PRINT_DETAIL(...) (printf("[%s, Line:%u, %s()]",\
                        __FILE__,__LINE__,__func__),\
                        printf(__VA_ARGS__))
#define UDP_PRINT_DBG(...) (printf("[%s, Line:%u, %s()]",\
                        __FILE__,__LINE__,__func__),\
                        printf(KGREEN),\
                        printf(" "__VA_ARGS__),\
                        printf(RESET))
#define UDP_PRINT_FATAL(...) (printf("[%s, Line:%u, %s()]",\
                        __FILE__,__LINE__,__func__),\
                        printf(KORANGE),\
                        printf(" "__VA_ARGS__),\
                        printf(RESET))
#define UDP_PRINT_EMERG(...) (printf("[%s, Line:%u, %s()]",\
                        __FILE__,__LINE__,__func__),\
                        printf(KRED),\
                        printf(" "__VA_ARGS__),\
                        printf(RESET))
#define UDP_PRINT_ALERT(...) (printf("[%s, Line:%u, %s()]",\
                        __FILE__,__LINE__,__func__),\
                        printf(KSALMON),\
                        printf(" "__VA_ARGS__),\
                        printf(RESET))
#define UDP_PRINT_CRIT(...) (printf("[%s, Line:%u, %s()]",\
                            __FILE__,__LINE__,__func__),\
                            printf(KMAGENTA),\
                            printf(" "__VA_ARGS__),\
                            printf(RESET))
#define UDP_PRINT_ERR(...) (printf("[%s, Line:%u, %s()]",\
                        __FILE__,__LINE__,__func__),\
                        printf(KPINK),\
                        printf(" "__VA_ARGS__),\
                        printf(RESET))
#define UDP_PRINT_WARN(...) (printf("[%s, Line:%u, %s()]",\
                        __FILE__,__LINE__,__func__),\
                        printf(KYELLOW),\
                        printf(" "__VA_ARGS__),\
                        printf(RESET))
#define UDP_PRINT_NOTICE(...) (printf("[%s, Line:%u, %s()]",\
                        __FILE__,__LINE__,__func__),\
                        printf(KLIMEGREEN),\
                        printf(" "__VA_ARGS__),\
                        printf(RESET))
#define UDP_PRINT_INFO(...) (printf("[%s, Line:%u, %s()]",\
                            __FILE__,__LINE__,__func__),\
                            printf(KBLUE),\
                            printf(" "__VA_ARGS__),\
                            printf(RESET))
#define UDP_PRINT_PACKET(a, b) (printf("[%s, Line:%u, %s()] ",\
                            __FILE__,__LINE__,__func__),\
                            printf(KCYAN),\
                            printf(a":["),udp_print_packet(b),printf("]\n"),\
                            printf(RESET))
#define UDP_PRINT_TIMEVAL(a, b) (printf("[%s, Line:%u, %s()]",\
                            __FILE__,__LINE__,__func__),\
                            printf(KGREEN),\
                            printf(" %s", a), \
                             udp_print_timeval(b),\
                             printf(RESET))
#else
#define UDP_PRINT(...)
#define UDP_PRINT_DETAIL(...)
#define UDP_PRINT_DBG(...)
#define UDP_PRINT_FATAL(...)
#define UDP_PRINT_EMERG(...)
#define UDP_PRINT_ALERT(...)
#define UDP_PRINT_CRIT(...)
#define UDP_PRINT_ERR(...)
#define UDP_PRINT_WARN(...)
#define UDP_PRINT_NOTICE(...)
#define UDP_PRINT_INFO(...)
#define UDP_PRINT_HEX_STRING(a, b, c)
#define UDP_PRINT_TIMEVAL(a, b)
#endif

#define udpfree(p) do { \
                   if (p) {     \
                     frfree(p); \
                     p = NULL;  \
                   } \
                 } while(0)

int udp_detect(Conntrack *p_st_conn, Apm_packet *p_st_packet);

int udp_analysis(Conntrack *p_st_conn, Apm_packet *p_st_packet, Frhash_header *p_st_hash_report);

int udp_session_destroy(void *p_private_session);

#endif
